#ifndef CONNBUFFER_H_
#define CONNBUFFER_H_

#ifdef __cplusplus
extern "C" {
#endif

#include <assert.h>
#include "mm.h"

struct connbuffer_t;

struct connbuffer_t* connbuffer_init(int buffer_size, int threshold_hint);

int connbuffer_release(struct connbuffer_t* connbuffer);

// read data in buffer to dest
// return: read bytes
int connbuffer_read(struct connbuffer_t* connbuffer, char* dest, int len);

int connbuffer_read_nocopy(struct connbuffer_t* connbuffer, int len);

// only read and not pick out
// return: read bytes
int connbuffer_peek(struct connbuffer_t* connbuffer, char* dest, int len);

// write data from src to connbuffer
// return: write bytes
int connbuffer_write(struct connbuffer_t* connbuffer, const char* src, int len);

int connbuffer_write_nocopy(struct connbuffer_t* connbuffer, int len);

int connbuffer_reset(struct connbuffer_t* connbuffer);

const char* connbuffer_debug(struct connbuffer_t* connbuffer);

char* connbuffer_read_buffer(struct connbuffer_t* connbuffer);
  
char* connbuffer_write_buffer(struct connbuffer_t* connbuffer);

int connbuffer_read_len(struct connbuffer_t* connbuffer);

int connbuffer_write_len(struct connbuffer_t* connbuffer);


#ifdef __cplusplus
}
#endif

#endif // CONNBUFFER_H_

